<script>
	 
	import { islog, netProgramLogin, netWechatLogin, setAppCtx } from '@/api/login.js'
	import { myRequest, dingRequest } from '@/util/api.js';
	export default {
		onLaunch() {
			//登录
			uni.setStorageSync('isAuth',true)
			
			const updateManager = uni.getUpdateManager();
			updateManager.onCheckForUpdate(function (res) {
			    // 请求完新版本信息的回调
			    if(res.hasUpdate){
				    updateManager.onUpdateReady(function (res) {
						updateManager.applyUpdate();
					 //    uni.showModal({
					 //        title: '更新提示',
						//     content: '新版本已经准备好，是否重启应用？',
						// 	success(res) {
						// 		if (res.confirm) {
						// 			// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
						// 			updateManager.applyUpdate();
						// 		}
						// 	}
						// })
				    })
			    } 
			})
			
			 console.log("启动。。。。。。。。。。")
			let isLogin = !!(uni.getStorageSync('token')||'')
			 
			 	// #ifdef H5
				
				if (!isLogin && (navigator.userAgent.toLowerCase().indexOf("micromessenger") !== -1)) {
					console.log(window.location.href,window.location.host,'-----')
					let str = window.location.href
					if(str.indexOf('code') != -1) {
						let fir = Number(str.indexOf('=')) + 1
						let last = str.indexOf('&')
						let code = str.slice(fir,last)
						console.log(code,'=====')
						if(code) { 
							netWechatLogin(code,{}).then(res=>{
								if(res.data){ 
									setAppCtx(res.data)
									
									// #ifdef MP-DXX
									uni.redirectTo({
										url:'/pagesDxx/index/index'
									})
									// #endif
									
									// #ifndef MP-DXX
									uni.redirectTo({
										url:'/pages/index/index'
									})
									// #endif
								}
							}).catch(res=>{
								 
							}) 
						}
					} else {
						if(location.pathname.indexOf('/pages/daka/index/index') === -1) {
							let appid = "wxf78b7c11bf66b55e"//uni.getStorageSync('appid')
							if(appid){
								let oUrl = window.location.href;
								oUrl = encodeURIComponent(oUrl)
								window.location = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + appid +
									`&redirect_uri=${oUrl}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`
							}else{
								uni.showToast({
									title:'请在后台设置appid',
									icon:'none'
								})
							} 
						}
					}
				}
				// #endif
			// #ifdef MP
			// 小程序静默授权 
			if (!isLogin) {
				let provider = 'weixin'//await this.getProvider()
				uni.login({
					provider:provider,
					success(res) {
						if (res.code) console.log(res.code);
						netProgramLogin(res.code,{}).then(res=>{
							if(res.data){
								setAppCtx(res.data)
								
								// #ifdef MP-DXX
								uni.redirectTo({
									url:'/pagesDxx/index/index'
								})
								// #endif
								
								// #ifndef MP-DXX
								uni.redirectTo({
									url:'/pages/index/index'
								})
								// #endif
							}
						}).catch(res=>{
							 
						})
					},
					fail(){
						 
					}
				}) 
			}
			// #endif
			
		},
		onShow() {			
			
		},
		onHide() {
			
		},
		onShareAppMessage() {
			
		}
	}
</script>

<style  lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "uview-ui/index.scss";
	.valueActive {
		color: #333;
	}
	.icon_creat {
		position: fixed;
		z-index: 1;
		bottom: 180rpx;
		right: 80rpx;
	
		image {
			width: 80rpx;
			height: 80rpx;
			border-radius: 50%;
		}
	}
	
		/*每个页面公共css */
		@import "colorui/main.css";
		@import "colorui/icon.css";
		@import "colorui/animation.css";
	/* 引入 css */
		@import url('./static/font/iconfont.css');
	/*每个页面公共css */
	page {
		background-color: #f5f5f5;
		/* background-color: red; */
		font-size: 26rpx;
		color: #666;
	}
	/* 标题样式 */
	.title-style {
		padding: 20rpx 0 20rpx 24rpx;
		font-size: 28rpx;
		font-weight: 700;
	}
	.botsec{
		height:30rpx;
	}
	/* 全局按钮样式 */
	.btn_g {
		width: 590rpx;
		height: 80rpx;
		line-height: 80rpx;
		font-size: 28rpx;
		text-align: center;
		margin: 40rpx auto;
		color: #fff;
		border-radius: 40rpx;
		background:#03aa96;
	}
	.btn_g2 {
		width: 590rpx;
		height: 80rpx;
		line-height: 80rpx;
		font-size: 28rpx;
		text-align: center;
		margin: 40rpx auto;
		color: #03aa96;
		border-radius: 40rpx;
		background:#fff;
	}
	/* 单元格 */
	.industry_item_g {
		padding-right: 30rpx;
		display: flex;
		justify-content: space-between;
		height: 90rpx;
		line-height: 90rpx;
		border-bottom: 1rpx solid #EAEAEA;
	}
	
	/*按钮样式*/
	.button-hover{
		background:#03aa96;
		border-radius: 40rpx;
	}
	.uni-picker-container .uni-picker-action.uni-picker-action-confirm{
		color:#03AA96;
	}
	
	
	/*店销秀每个页面公共css */
	.content_dxx {
		background-image: linear-gradient(10deg,  #ffffff, #c8ebd0);
		// background-color: #c8ebd0;//#d9c2a3;
		height: 100vh;
	
		color: #666;
	}
</style>
